<?php
/**
 * Description of module
 *
 * @author Flame
 */

class module
{
	private $installed = array();

	function __construct()
	{
		if(!file_exists("cfg/modules.php"))
		{
			global $db;

			$file_cfg = fopen("cfg/modules.php", 'x+');
			fwrite($file_cfg, "<?php\n");

			$sql = "SELECT * FROM modules";
			$risultato = $db->query($sql);;
			while($row = mysql_fetch_assoc($risultato))
			{
                fwrite($file_cfg, '$this->$installed[\''.$row['name'].'\'] = "'.$row['path'].'";' . "\n");

				$this->$installed[$row['nome']] = $row['valore'];
			}

			fwrite($file_cfg, "?>");
			fclose($file_cfg);
		}
		else
		{
			include("cfg/modules.php");
		}
	}

    public function is_install($key)
    {
        if(isset($this->$installed[$key])) return true;
        return false;
    }

	public function get($key)
	{
		if($this->is_install($key))
		{
			return $this->$installed[$key];
		}
		else
		{
			return false;
		}
	}

    public function install($m,$p)
    {
    global $db;
        $sql = "INSERT INTO modules (name,path)  VALUES ('".$m."','".$p."')";
        $db->query($sql);
    unlink("cfg/modules.php");
    }

    public function remove($name)
    {
    global $db;
        $sql = "DELETE FROM modules WHERE name = '".$name."' LIMIT 1";
        $db->query($sql);
    unlink("cfg/modules.php");
    }
}

$module = new module();
?>
